package com.danbay.cloud.device.service;

import com.danbay.cloud.device.api.dto.DevicePositionDto;
import com.danbay.cloud.device.api.service.IDevicePositionService;
import com.danbay.cloud.device.entity.DevicePosition;
import com.danbay.cloud.device.mapper.DevicePositionMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class DevicePositionService implements IDevicePositionService {

    @Autowired
    private DevicePositionMapper devicePositionMapper;

    @Override
    public long addPosition(DevicePositionDto devicePositionDto) {
        //TODO 封装DevicePosition对象
        DevicePosition devicePosition = DevicePosition.builder().deviceId(devicePositionDto.getDeviceId()).build();
        devicePositionMapper.insert(devicePosition);
        return devicePosition.getId();
    }

    @Override
    public DevicePositionDto getPositionByDeviceId(String deviceId) {
        DevicePosition qdp = DevicePosition.builder().deviceId(deviceId).build();
        DevicePosition devicePosition = devicePositionMapper.selectOne(qdp);
        //TODO 补充完整返回对象
        return DevicePositionDto.builder().deviceId(deviceId).id(devicePosition.getId()).build();
    }
}
